/*
 * @Author: myw
 * @Email: 516378746@qq.com
 * @Date: 2020-03-03 15:00:36
 * @Descripttion: 
 */
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';

import { Observable } from "rxjs"

@Injectable({
    providedIn: 'root'
})
export class MaterialRelationService {

    private whsTreelUrl = '/api/warehouse/tree';
    getWhsTree(): Observable<any> {
        return this.http.get(this.whsTreelUrl, {}).pipe()
    }

    private materialUrl = '/api/material';
    getMaterialList(data): Observable<any> {
        return this.http.get(this.materialUrl + "?code=" + data.code + "&name=" + data.name + "&page=" + data.page + "&size=" + data.size, {}).pipe()
    }

    private stockUrl = "/api/stock";
    getMaterialRelation(data): Observable<any> {
        return this.http.get(this.stockUrl + "?warehouseId=" + data.warehouseId + "&warehouseAreaId=" + data.warehouseAreaId + "&materialCode=" + data.code + "&materialName=" + data.name + "&page=" + data.page + "&size=" + data.size, {}).pipe()
    }
    postMaterialRelation(data): Observable<any> {
        return this.http.post(this.stockUrl, data).pipe()
    }
    delMaterialRelations(data): Observable<any> {
        let _dataJson = {
            headers: new HttpHeaders({ 'Content-Type': 'application/json', }),
            body: data
        }
        return this.http.delete(this.stockUrl, _dataJson).pipe();
    }

    private getAllUrl = '/api/stock/getall';
    getAll(data): Observable<any> {
        let _data = {
            ...data
        }
        return this.http.get(this.getAllUrl, { params: _data }).pipe()
    }

    /**
      * @Author: myw
      * @Email: 516378746@qq.com
      * @Date: 2020-03-06 14:45:57
      * @UseComponent: 移库入库(moveware-apply)
      * @Descripttion: 根据物料编号获取对应的库房
      * @Return: 
      */
    private findWareByMaterialIdUrl: string = "/api/stock/findByMaterialId";
    findWareByMaterialId(data): Observable<any> {
        let _dataJson = {
            params: data
        }
        return this.http.get(this.findWareByMaterialIdUrl, _dataJson)
    }
    /**
     * @Author: myw
     * @Email: 516378746@qq.com
     * @Date: 2020-03-06 14:46:33
     * @UseComponent: 移库入库(moveware-apply)
     * @Descripttion: 根据物料编号,库房ID 获取对应的库区
     * @Return: 
     */
    private findWareAreaByMaterialIdUrl: string = "/api/stock/findByMidWareHouseId"
    findWareAreaByMaterialId(data): Observable<any> {
        let _dataJson = {
            params: data
        }
        return this.http.get(this.findWareAreaByMaterialIdUrl, _dataJson)
    }
    /**
     * @Author: myw
     * @Email: 516378746@qq.com
     * @Date: 2020-03-06 15:30:33
     * @UseComponent: 移库入库(moveware-apply)
     * @Descripttion: 根据 库房编号，库区编号，物料编号，查询库存批次
     * @Return: 
     */
    private findStockBatchByIdsUrl:string = "/api/stock/findStockBatchByIds"
    findStockBatchByIds(data):Observable<any>{
        let _dataJson = {
            params : data
        }
        return this.http.get(this.findStockBatchByIdsUrl, _dataJson)
    }

    constructor(
        private http: HttpClient
    ) { }
}
